#include "gofgame/jumpdown/layer/ListCell.h"

using namespace gofgame::jumpdown::layer;
using namespace cocos2d;

ListCell *ListCell::createListCell(int num, std::string name, int score) {
	ListCell *lc = new ListCell();
	lc->m_rank = num;
	lc->m_name = name;
	lc->m_score = score;
	if(!lc->init()) {
		delete lc;
		return nullptr;
	}
	return lc;
}

int ListCell::getRank(){
	return this->m_rank;
}

bool ListCell::init(){
	float tableWidth = CCDirector::sharedDirector()->getWinSize().width * 0.8F;
	char str[10];
	sprintf(str,"%d",this->m_rank);
	CCLabelTTF *labelNum = CCLabelTTF::create(str,"",30);
	labelNum->setColor(ccc3(0,0,0));
	labelNum->setAnchorPoint(ccp(0, 0));
	labelNum->setPosition(ccp(tableWidth * 0.1F, 0));
	CCLabelTTF *labelName = CCLabelTTF::create(this->m_name.c_str(),"",30);
	labelName->setColor(ccc3(0,0,0));
	labelName->setAnchorPoint(ccp(0, 0));
	labelName->setPosition(ccp(tableWidth * 0.4F,0));
	sprintf(str,"%d",this->m_score);
	CCLabelTTF *labelScore = CCLabelTTF::create(str,"",30);
	labelScore->setColor(ccc3(0,0,0));
	labelScore->setAnchorPoint(ccp(0, 0));
	labelScore->setPosition(ccp(tableWidth * 0.8F,0));
	this->addChild(labelNum);
	this->addChild(labelName);
	this->addChild(labelScore);
	return true;
}